package edu.tyut.lingyunxing.controller;

import edu.tyut.lingyunxing.common.R;
import edu.tyut.lingyunxing.pojo.Airport;
import edu.tyut.lingyunxing.service.AirportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * DateTime: 2025/6/24 - 23:58
 * Author: Ycs
 */
@RestController
@RequestMapping("/airport")
@Slf4j
public class AirportController {
    
    @Resource
    AirportService service;
    
    @PostMapping("/add")
    public R<String> add(@RequestBody Airport airport, HttpServletRequest request) {
        if (airport.getName() != null) {
            service.save(airport);
            return R.success("成功！");
        } else {
            return R.error("请输入名称");
        }
    }
    
    @GetMapping("/list")
    public R<List<Airport>> list(HttpServletRequest request) {
        return R.success(service.list());
    }
    
}
